/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package autoUpdate;

import com.google.gdata.data.photos.AlbumEntry;
import com.google.gdata.data.photos.PhotoEntry;
import configuration.Defaults;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;
import picasaphotomanager.PicasaSession;
import picasaphotomanager.PicasaSessionManager;

/**
 *
 * @author paskud
 */
public class WatchEntry {
    private String _id;
    private String _parentId;
    private Long _picasaAccountId;
    private Date _lastUpdatedLocally = new Date(0);
    private Date _lastUpdatedOnline = new Date(0);
    private String _localPath;
    private boolean _enabled = true;
    private String _title;
    private boolean _downloadOnce;
    private String _hash = null;
    private String _thumbnailUrl;
    private long _onlineSize;
    private String _mediaUrl;
    private String _photoResolution = Defaults.DefaultResolution.toString();
    private Map<String, WatchEntry> _children = new HashMap<String, WatchEntry>();

    
    public WatchEntry() {
    }

    public WatchEntry(AlbumEntry album, String localPath)  {
        PicasaSession session = PicasaSessionManager.getSession(album.getUsername());

        _picasaAccountId = session.PicasaAccount.getId();
        _id = album.getId().substring(album.getId().lastIndexOf("/") + 1);
        _title = album.getTitle().getPlainText();
        _localPath = localPath;

        _parentId = null;
        _lastUpdatedOnline = new Date(album.getUpdated().getValue());
        _thumbnailUrl = album.getMediaThumbnails().get(0).getUrl();
        _mediaUrl = null;
        _onlineSize = album.getBytesUsed();
        
        
    }

    public WatchEntry(PhotoEntry photo, String localPath, Long picasaAccountId)  {
        _picasaAccountId = picasaAccountId;
        _localPath = localPath;
        
        if (photo != null) {
            _parentId = null;
            _id = photo.getId();
            _title = photo.getTitle().getPlainText();
            _lastUpdatedOnline = new Date(photo.getUpdated().getValue());
            _thumbnailUrl = photo.getMediaThumbnails().get(0).getUrl();
            _mediaUrl = photo.getMediaContents().get(0).getUrl();
            _onlineSize = photo.getSizeExt().getValue(); 
            _parentId = photo.getAlbumId();
        }
    }

    /**
     * @return the _localPath
     */
    public String getLocalPath() {
        return _localPath;
    }

    /**
     * @param localPath the _localPath to set
     */
    public void setLocalPath(String localPath) {
        this._localPath = localPath;
    }

    /**
     * @return the _albumId
     */
    public String getId() {
        return _id;
    }


    /**
     * @return the _albumOwner
     */
    public Long getAlbumOwner() {
        return _picasaAccountId;
    }

    /**
     * @param albumOwner the _albumOwner to set
     */
    public void setAlbumOwner(Long albumOwner) {
        this._picasaAccountId = albumOwner;
    }

    /**
     * @return the _lastUpdated
     */
    public Date getLastUpdatedLocally() {
        return _lastUpdatedLocally;
    }

    /**
     * @param lastUpdated the _lastUpdated to set
     */
    public void setLastUpdatedLocally(Date lastUpdated) {
        this._lastUpdatedLocally = lastUpdated;
    }

    /**
     * @return the enabled
     */
    public boolean isEnabled() {
        return _enabled;
    }

    /**
     * @param enabled the enabled to set
     */
    public void setEnabled(boolean enabled) {
        this._enabled = enabled;
    }

    /**
     * @return the _albumTitle
     */
    public String getTitle() {
        return _title;
    }

    /**
     * @param albumTitle the _albumTitle to set
     */
    public void setTitle(String albumTitle) {
        this._title = albumTitle;
    }

    /**
     * @return the _downloadOnce
     */
    public boolean isDownloadOnce() {
        return _downloadOnce;
    }

    /**
     * @param downloadOnce the _downloadOnce to set
     */
    public void setDownloadOnce(boolean downloadOnce) {
        this._downloadOnce = downloadOnce;
    }

    /**
     * @return the _children
     */
    public Map<String, WatchEntry> getChildren() {
        return _children;
    }

    /**
     * @param children the _children to set
     */
    public void setChildren(Map<String, WatchEntry> children) {
        this._children = children;
    }

    /**
     * @return the _hash
     */
    public String getHash() {
        return _hash;
    }

    /**
     * @param hash the _hash to set
     */
    public void setHash(String hash) {
        this._hash = hash;
    }

    /**
     * @return the _photoResolution
     */
    public String getPhotoResolution() {
        return _photoResolution;
    }

    /**
     * @param photoResolution the _photoResolution to set
     */
    public void setPhotoResolution(String photoResolution) {
        this._photoResolution = photoResolution;
    }

    /**
     * @return the _parentId
     */
    //public String getParentId() {
     //   return _parentId;
    //}

    /**
     * @param parentId the _parentId to set
     */
    public void setParentId(String parentId) {
        this._parentId = parentId;
    }

    /**
     * @return the _thumbnailUrl
     */
    public String getThumbnailUrl() {
        return _thumbnailUrl;
    }

    /**
     * @param thumbnailUrl the _thumbnailUrl to set
     */
    public void setThumbnailUrl(String thumbnailUrl) {
        this._thumbnailUrl = thumbnailUrl;
    }

    /**
     * @return the _mediaUrl
     */
    public String getMediaUrl() {
        return _mediaUrl;
    }

    /**
     * @param mediaUrl the _mediaUrl to set
     */
    public void setMediaUrl(String mediaUrl) {
        this._mediaUrl = mediaUrl;
    }

    /**
     * @return the _onlineSize
     */
    public long getOnlineSize() {
        return _onlineSize;
    }

    /**
     * @param onlineSize the _onlineSize to set
     */
    public void setOnlineSize(long onlineSize) {
        this._onlineSize = onlineSize;
    }

    /**
     * @return the _lastUpdatedOnline
     */
    public Date getLastUpdatedOnline() {
        return _lastUpdatedOnline;
    }

    /**
     * @param lastUpdatedOnline the _lastUpdatedOnline to set
     */
    public void setLastUpdatedOnline(Date lastUpdatedOnline) {
        this._lastUpdatedOnline = lastUpdatedOnline;
    }

    /**
     * @return the _parentId
     */
    public String getParentId() {
        return _parentId;
    }

}
